package senders;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public abstract class Sender {
    protected Connection connection;
    protected Channel channel;
    protected String queueName;
    protected boolean persistence;
    protected String exchangeName;
    protected String exchangeType;
    protected String routingKey;

    public  Sender(
            Connection connection,
            String queueName,
            boolean persistence,
            String exchangeName,
            String exchangeType,
            String routingKey) throws IOException {
        this.connection = connection;
        this.channel = connection.createChannel();
        this.queueName = queueName;
        this.persistence = persistence;
        this.exchangeName = exchangeName;
        this.exchangeType = exchangeType;
        this.routingKey = routingKey;
    }

    public void closeConnection() throws IOException {
        connection.close();
    }

    public void closeChannel() throws IOException, TimeoutException {
        channel.close();
    }

    public abstract void send(String s) throws IOException, TimeoutException;
}
